using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using InfraStructureLayer;
using EntityLayer;
using DataLayer;
using DataAccessLayer;

namespace BusinessLayer
{
    public class busMails : BusinessBase
    {

        public void SendMail(int mailId, object[] mailParams)
        {
            try
            {
                SmtpClient insSmtpClient = new SmtpClient(CurrentContext.Parameters["MailServer"].ToString());
                insSmtpClient.Credentials = new System.Net.NetworkCredential(CurrentContext.Parameters["MailUserName"].ToString(), CurrentContext.Parameters["MailUserPassword"].ToString());
                MailMessage mm = new MailMessage(CurrentContext.Parameters["MailFrom"].ToString(), CurrentContext.Parameters["MailTo"].ToString());
                mm.BodyEncoding = Encoding.GetEncoding("iso-8859-9");
                mm.SubjectEncoding = Encoding.GetEncoding("iso-8859-9");
                mm.IsBodyHtml = true;

                entMails insEntMails = new entMails();
                insEntMails.MailId = mailId;
                datMails insDatMails = new datMails();

                insDatMails.SelectMailsByMailId(insEntMails, new DbConnector());

                mm.Body = String.Format(insEntMails.MailBody, mailParams);
                mm.Subject = insEntMails.MailSubject;

                insSmtpClient.Send(mm);

            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
    }
}
